package com.ldf.jrtsp.handler;

import com.ldf.jrtsp.parser.RtspDataParser;
import com.ldf.jrtsp.player.RtspPlayer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.ldf.jrtsp.constants.RtspConstants.RTSP_OK;
import static com.ldf.jrtsp.enums.RtspOptionsType.PLAY;
import static com.ldf.jrtsp.enums.RtspOptionsType.SETUP;

/**
 * play reply handle
 *
 * @author lidaofu
 * @since 2024/6/19
 **/
public class RtspPlayReplyHandle implements RtspReplyHandle {
    private final static Logger log = LoggerFactory.getLogger(RtspPlayReplyHandle.class);

    @Override
    public void handle(RtspPlayer player,RtspDataParser rtspDataParser) {
        if (rtspDataParser.getResponse().equals(RTSP_OK)) {
            log.info("rtsp play reply is {}", rtspDataParser.getResponse());
            player.setSession(rtspDataParser.getHeaders().get("Session"));
            player.createRtpOverCodecParser();
        } else {
            log.warn("rtsp play reply is {}", rtspDataParser.getResponse());
        }
        player.sendOptionsCallBack(PLAY,rtspDataParser);
    }
}
